import { createContext, useContext } from 'react';

import { ApiDictionaryType } from '@donnu-prod-practice/api';

const ApiDictionaryContext = createContext<ApiDictionaryType | null>(null);

export const ApiDictionaryProvider = ApiDictionaryContext.Provider;

export const useApiDictionary = (): ApiDictionaryType => {
  const apiDictionary = useContext(ApiDictionaryContext);

  if (!apiDictionary) throw new Error('useApiDictionary must be used within the ApiDictionaryProvider');

  return apiDictionary;
};
